load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)
load("//tools/lint:lint.bzl", "add_lint_tests")
load("//tools/skylark:test_tags.bzl", "vtk_test_tags")

package(default_visibility = ["//visibility:private"])

drake_cc_package_library(
    name = "render_vtk",
    visibility = ["//visibility:public"],
    deps = [
        ":factory",
        ":render_engine_vtk_params",
    ],
)

drake_cc_library(
    name = "render_engine_vtk_params",
    srcs = ["render_engine_vtk_params.cc"],
    hdrs = ["render_engine_vtk_params.h"],
    visibility = ["//visibility:public"],
    deps = [
        "//common:essential",
        "//common:name_value",
        "//geometry/render:light_parameter",
        "//geometry/render:render_label",
    ],
)

drake_cc_library(
    name = "factory",
    srcs = ["factory.cc"],
    hdrs = ["factory.h"],
    visibility = ["//visibility:public"],
    interface_deps = [
        "//geometry/render:render_engine",
        ":render_engine_vtk_params",
    ],
    deps = [
        ":internal_render_engine_vtk",
    ],
)

drake_cc_library(
    name = "internal_render_engine_vtk",
    srcs = ["internal_render_engine_vtk.cc"],
    hdrs = ["internal_render_engine_vtk.h"],
    internal = True,
    visibility = [
        "//geometry/render_gltf_client:__pkg__",
    ],
    deps = [
        ":internal_render_engine_vtk_base",
        ":internal_vtk_util",
        "//common",
        "//geometry/render:render_engine",
        "//geometry/render/shaders:depth_shaders",
        "//geometry/render_vtk:render_engine_vtk_params",
        "//systems/sensors:color_palette",
        "//systems/sensors:vtk_diagnostic_event_observer",
        "@eigen",
        "@vtk_internal//:vtkCommonCore",
        "@vtk_internal//:vtkCommonExecutionModel",
        "@vtk_internal//:vtkCommonTransforms",
        "@vtk_internal//:vtkFiltersSources",
        "@vtk_internal//:vtkIOGeometry",
        "@vtk_internal//:vtkIOImage",
        "@vtk_internal//:vtkIOImport",
        "@vtk_internal//:vtkImagingCore",
        "@vtk_internal//:vtkRenderingCore",
        "@vtk_internal//:vtkRenderingOpenGL2",
    ],
)

drake_cc_library(
    name = "internal_render_engine_vtk_base",
    srcs = ["internal_render_engine_vtk_base.cc"],
    hdrs = ["internal_render_engine_vtk_base.h"],
    internal = True,
    visibility = ["//visibility:private"],
    deps = [
        "//common:scope_exit",
        "//geometry:geometry_roles",
        "//geometry:shape_specification",
        "//geometry/render:render_material",
        "//geometry/render:render_mesh",
        "@vtk_internal//:vtkCommonCore",
        "@vtk_internal//:vtkCommonDataModel",
        "@vtk_internal//:vtkCommonExecutionModel",
        "@vtk_internal//:vtkCommonTransforms",
        "@vtk_internal//:vtkFiltersGeneral",
        "@vtk_internal//:vtkFiltersSources",
    ],
)

drake_cc_library(
    name = "internal_vtk_util",
    srcs = ["internal_vtk_util.cc"],
    hdrs = ["internal_vtk_util.h"],
    internal = True,
    visibility = ["//visibility:private"],
    deps = [
        "//common:essential",
        "//math:geometric_transform",
        "@eigen",
        "@vtk_internal//:vtkCommonCore",
        "@vtk_internal//:vtkCommonTransforms",
        "@vtk_internal//:vtkFiltersSources",
    ],
)

drake_cc_googletest(
    name = "internal_render_engine_vtk_test",
    timeout = "moderate",
    args = select({
        # Most test cases do not render correctly on macOS arm64 CI. Instead of
        # trying to select the few that randomly happen to pass, we'll skip all
        # of them. TODO(#19424) Re-enable the tests.
        "@platforms//cpu:arm64": [
            "--gtest_filter=-*",
        ],
        "//conditions:default": [],
    }),
    data = [
        "//geometry:environment_maps",
        "//geometry/render:test_models",
    ],
    tags = vtk_test_tags(),
    deps = [
        ":internal_render_engine_vtk",
        "//common:find_resource",
        "//common/test_utilities",
        "//geometry/test_utilities:dummy_render_engine",
        "//math:geometric_transform",
        "//systems/sensors/test_utilities:image_compare",
        "@vtk_internal//:vtkIOImage",
        "@vtk_internal//:vtkRenderingCore",
        "@vtk_internal//:vtkRenderingOpenGL2",
    ],
)

config_setting(
    name = "osx",
    constraint_values = ["@platforms//os:osx"],
)

drake_cc_googletest(
    name = "internal_render_engine_vtk_no_display_test",
    args = select({
        # This test only makes sense on Linux, because only Linux uses the
        # DISPLAY environment variable to connect to the graphics system.
        ":osx": ["--gtest_filter=-*"],
        "//conditions:default": [],
    }),
    tags = vtk_test_tags(),
    deps = [
        ":factory",
        "//common/test_utilities",
    ],
)

drake_cc_googletest(
    name = "internal_vtk_util_test",
    deps = [
        ":internal_vtk_util",
        "@vtk_internal//:vtkCommonCore",
        "@vtk_internal//:vtkCommonDataModel",
        "@vtk_internal//:vtkFiltersSources",
    ],
)

drake_cc_googletest(
    name = "render_engine_vtk_params_test",
    deps = [
        ":render_engine_vtk_params",
        "//common/yaml",
    ],
)

add_lint_tests()
